{include file="common/head"}
<link    rel="stylesheet"    href="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.js"></script>    
</head>
<body style="">
    <div class="container p-3 my-3 " style="max-width: 900px;"  >
    <h2>考题编辑</h2>
    <form method="post" enctype="multipart/form-data" action="/index.php/question/edit">
      <input type="hidden" name="id" value="{$data.id}" />
      <div class="mb-3 row" >
        <div class="col">
          <label for="type" class="form-label">考题类型:</label>
          <span style="border:1px solid #ccc;padding: 4px 10px;">
            <input type="radio" class="form-check-input" id="radio3" name="type" value="1" {if $data.type==1} checked {/if} /> 
            <label class="form-check-label" for="radio3">单选题</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio4" name="type" value="2" {if $data.type==2} checked {/if} />
            <label class="form-check-label" for="radio4">多选题</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio5" name="type" value="3" {if $data.type==3} checked {/if} />
            <label class="form-check-label" for="radio5">判断题</label>&nbsp;&nbsp;       
          </span>
        </div>
        <div class="col">
          <label for="subject" class="form-label">科目:</label>
          <span style="border:1px solid #ccc;padding: 4px 10px;">
            <input type="radio" class="form-check-input" id="radio6" name="subject" value="1" {if $data.subject==1} checked {/if} /> 
            <label class="form-check-label" for="radio6">科目一</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio7" name="subject" value="4" {if $data.subject==4} checked {/if} />
            <label class="form-check-label" for="radio7">科目四</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio12" name="subject" value="" {if $data.subject==''} checked {/if} />
            <label class="form-check-label" for="radio12">不选</label>            
          </span>
        </div>

      </div>

      <div class="row">
        <div class="col">
          <label for="model" class="form-label">驾照类型:</label>
          <span style="border:1px solid #ccc;padding: 4px 10px;">
            <input type="radio" class="form-check-input" id="radio8" name="model" value="C1" {if $data.model=='C1'} checked {/if} /> 
            <label class="form-check-label" for="radio8">C1</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio9" name="model" value="C2" {if $data.model=='C2'} checked {/if} />
            <label class="form-check-label" for="radio9">C2</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio10" name="model" value="D,E,F" {if $data.model=='D,E,F'} checked {/if}  /> 
            <label class="form-check-label" for="radio10">D,E,F</label>&nbsp;&nbsp;
            <input type="radio" class="form-check-input" id="radio11" name="model" value="SL" {if $data.model=='SL'} checked {/if} />
            <label class="form-check-label" for="radio11">三力测试</label>            
          </span>
        </div>        
      </div>

      <div class="mb-3 mt-3">
        <label for="title" class="form-label">问题:</label>
        <textarea class="form-control" id="title" name="title" style="height: 60px;">{$data.title}</textarea>
      </div>

      <div style="border:1px solid #ccc;padding:10px;">

        {foreach $data.options as $k=>$kv}
        <div class="mb-3 row">
          <div class="col-1" style="line-height: 28px;">{$kv['key']}：</div>
          <div class="col-11"><input type="text" class="form-control" id="option{$k+1}" name="option{$k+1}" value="{$kv['val']}" placeholder="" /></div>
        </div>
        {/foreach}
<!--         {if $data.type<3}
        <div class="mb-3 row" >
          <div class="col-1">C:</div>
          <div class="col-11">
            <input type="text" class="form-control" id="option3" name="option3" value="" placeholder="" />
          </div>
        </div>      
        <div class="mb-3 row" >
          <div class="col-1">D:</div>
          <div class="col-11">
            <input type="text" class="form-control" id="option4" name="option4" value="" placeholder="" />
          </div>
        </div>
        {/if} -->




    <br/>
      <div class="mb-3">
        <label for="answer" class="form-label">正确答案(格式:单选A或B,多选A,B的格式)</label>
        <input type="text" class="form-control" id="answer" name="answer" value="{$data.answer}" placeholder="" />
      </div>
      <div class="mb-3 ">
        <label for="number" class="form-label">分值:</label>
        <input type="number" class="form-control"  id="number" name="number" value="1" min="1" max="5" placeholder="" />          
      </div>

      <div class="mb-3">
        <label for="desc" class="form-label">问题分析:</label>
        <textarea class="form-control" id="desc" name="desc" style="height: 60px;">{$data.desc}</textarea>
      </div>


      <div class="mb-3">
        <img src="{$data.image}" style="width:100px;" />
        <label for="file" class="form-label">上传图片(Image):</label>
        <input type="file"  name="file" /> 
      </div>

      <div class="mb-3">
        <label for="status" class="form-label">是否启用:</label>
          <input type="radio" class="form-check-input" id="radio1" name="status" value="1" {if $data.status==1}checked{/if} /> 
          <label class="form-check-label" for="radio1">启用</label>
          <input type="radio" class="form-check-input" id="radio2" name="status" value="2" {if $data.status==2}checked{/if}/>
          <label class="form-check-label" for="radio2">停用</label>
       </div>

      <button  type="button" class="btn btn-primary" onclick="doSave()">保存(Save)</button>
    </form>
    </div>

<script type="text/javascript">
  function doSave(){
    // if(!$("#name").val() || !$("#price").val() || !$("#discount").val()){
    //   layer.msg("别瞎闹！",function(){});
    //   $("#discount").val(1);
    //   return false;
    // }
    $('form').submit();
  }

    var editor = Jodit.make('#desc',{
      toolbarButtonSize: 'small',
    });

  $(document).ready(function(){
    $("input[name='type']").on('click',function(){
      var type =$(this).val();
      console.log(type==1);
       // if(type==3){
       //   $("#option1").val('正确');
       //   $("#option2").val('错误');
       //   $("#option3").parents('.row').hide();
       //   $("#option4").parents('.row').hide();
       // }else{
       //   console.log('show');
       //   $("#option1").val('');
       //   $("#option2").val('');
       //   $("#option3").parents('.row').show();
       //   $("#option4").parents('.row').show();
       // }
    })

      $("input[name='subject']").on('click',function(){
        var subject = $(this).val();
        if(subject==4){
          $("#number").val(2);
        }else{
          $("#number").val(1);
        }
      });
    $("#discount,#price").on('blur',function(){
      var price = $("#price").val();
      var ds = $("#discount").val();

      if(isNaN(ds) || ds<0.1 || ds>1){
        layer.msg('折扣错误！');
        $("#discount").val(1);
      }else{
        $("#price1").val(($("#price").val()*ds).toFixed(2));
      }
    })
  })  
</script>


</body>
</html>
